#!/usr/bin/python
# -*- coding: utf-8 -*-


'''
Created on 2013-6-25

@author: lyj
'''


from bsddb import db


database_folder = r'l:\_DevProject.Aptana3\demobsddb'

# 打印版本
print db.DB_VERSION_STRING
# 初始化数据库环境(DBEnv)
env = db.DBEnv()
# 打开数据库环境
# http://docs.oracle.com/cd/E17076_03/html/api_reference/CXX/frame_main.html
env.open(database_folder, db.DB_THREAD | db.DB_INIT_MPOOL | db.DB_INIT_LOCK | db.DB_CREATE)
# 获取锁ID
l_id = env.lock_id()
print 'locker ID: %s' % l_id
# 获取一个锁，返回DBLock对象
lock = env.lock_get(l_id, 'some locked thing', db.DB_LOCK_WRITE)
print "Aquired lock: %s" % lock
# 释放一个锁
env.lock_put(lock)
print "Released lock: %s" % lock
# 释放锁ID
env.lock_id_free(l_id)
